// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 * Creator: yanking
 * Create time: 2022-03-02 21:16
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.Greedy;

public class BalancedStringSplit {
    public int balancedStringSplit(String s) {
        // 分割平衡字符串 -> 贪心算法-> 平衡的字符串长度尽可能小
        int n = s.length();
        int lSum = 0;
        int rSum = 0;
        int ans = 0;
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            if (c == 'L') {
                lSum++;
            } else {
                rSum++;
            }
            if (lSum == rSum) {
                ans++;
            }
        }
        return ans;
    }

}
